#pragma once
#include "Car.h"
#include "ParkingLot.h"
#include <iostream> 
#include <map>
#include <string>
#include <fstream>
//using namespace std;
using namespace std;

class ParkinglotDB
{
private:
	bool autoprint;
	std::map <int,Car> Car_list;
	std::map <int,Car>::iterator it; 

	std::map <int,ParkingLot> ParkingLot_list;
	std::map <int,ParkingLot>::iterator Lotit; 

	std::map <int,Car> Eligible_list;

	int	SlotsNum; //states the number of slots in the parking lot 
	int TakenSlots; //states how many slots are taken 

	int CarsNum;	//the number of cars that entered today 
	int CurrentCarsNum; //the number of cars that occupy the parking lot

	ParkinglotDB(void){};
	~ParkinglotDB(void){};

	std::map<int, Car>::iterator FindCar(int license_plate);

	char tmpc[300];
	public:
	void InitLot();//Initialization of the parking lot

	// this is how you get the singleton object:
	static ParkinglotDB &instance (void)
	{
		static ParkinglotDB inst;
		return inst;
	}
	void CarEntered(int car_id);			/*this will generate a new car in the parking lot*/
	void CarExits(int car_id);				/*this will delete a car from the parking lot*/
	int IsParkingAvailble(int parking_id, string &s); /* return -1 if parking number parking_id is free, else retruns LP of the parking car*/
	bool SetLicensePlate (int car_id, int license_plate);/*sets the license plate of an existing car, returns false if car_id is not in the database*/
	bool CarParked (int car_id, float x, float y); 	/*sets the parking place of an existing car, returns false if car_id is not in the database */
	int CarUnparked(int x, int y);			/*returns the car_id of the car in the parking place of (x,y), and updating the database accordingly*/
	int WhereIsMyCar(int license_plate, string &s);	/*returns some description of the car location , -2 if no such car, -1 if not parking yet (traveling)*/ 
	void PrintOccupiedSpots();				/*prints the occupied parking places*/ 
	void PrintLogToFile();					/* prints log to TXT file the describes for every parking is it empty or who parking there, and when he entered to the parking lot*/
	bool isThisParkingSlot(int x, int y);	/*return true if the current location is a parking space*/
	void AutoPrint();						/*Triggers the auto print option (printing by default)*/ 

	/*					these are the new functions				*/
	int HowManySlotsFree(string &s);							/*2States how many parking slots are free*/
	void HowLongCarIn(int license_plate,string &s);			/*3States how long was the car in the lot*/
	void TheMostWantedSlot(string &s);						/*4Returns the most wanted slot in the prking lot*/ 
	void HowManyEntered(string &s);						/*5Returns the number of cars that entered to the parking lot*/
	void NumOfTimes(int license_plate,string &s);			/*6Returns the number of times the car entered to the parking lot*/ 
	bool IsEligible(int license_plate,string &s);				/*7Returns true if the car is aligable to enter the lot*/ 
	void WhenEntered(int license_plate,string &s);			/*12 rerurns the time in which the car entered to the parking lot*/ 
};